//package com.jihui.enterprise.event;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.jihui.enterprise.Account;
//import com.jihui.enterprise.common.SmsTemplateCodeEnum;
//import com.jihui.enterprise.domain.model.AccountRepository;
//import com.jihui.enterprise.domain.service.AccountService;
//import com.jihui.common.constant.YtxKafkaTopics;
//import org.apache.commons.collections.MapUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.kafka.annotation.KafkaListener;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 售后事件
// *
// * @author hxz
// * @since 2017/03/20 18:54
// */
//@Component
//public class DisputeEvent {
//    @Autowired
//    private ObjectMapper objectMapper;
//    @Autowired
//    private AccountService accountService;
//    @Autowired
//    private AccountRepository accountRepository;
//
//    private final Logger logger = LoggerFactory.getLogger(getClass());
//
//    //售后同意退款
//    @KafkaListener(topics = YtxKafkaTopics.CRM_AGREE_REFUND)
//    public void processCrmAgreeRefund(String message) {
//        logger.info("收到售后同意退款消息：{}", message);
//        try {
//            Map map = objectMapper.readValue(message, Map.class);
//
//            Long buyerAccountId = MapUtils.getLong(map,"buyerAccountId");
//            Account account = accountRepository.findOne(buyerAccountId);
//            if(account != null) {
//                String amount = String.valueOf(map.get("amount"));
//                String ip = String.valueOf(map.get("ip"));
//                Map<String, String> params = new HashMap<>();
//                params.put("price", amount);
//                accountService.sendYtxSms(account.getMobile(), SmsTemplateCodeEnum.SMS_66635248.getCode(), params, ip);
//            }
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//    //售后同意退货
//    @KafkaListener(topics = YtxKafkaTopics.CRM_AGREE_RETURN)
//    public void processCrmAgreeReturn(String message) {
//        logger.info("收到售后同意退货消息：{}", message);
//        try {
//            Map map = objectMapper.readValue(message, Map.class);
//
//            Long buyerAccountId = MapUtils.getLong(map,"buyerAccountId");
//            Account account = accountRepository.findOne(buyerAccountId);
//            if(account != null) {
//                String disputeNo = String.valueOf(map.get("disputeNo"));
//                String ip = String.valueOf(map.get("ip"));
//                Map<String, String> params = new HashMap<>();
//                params.put("price", disputeNo);
//                accountService.sendYtxSms(account.getMobile(), SmsTemplateCodeEnum.SMS_66635247.getCode(), params, ip);
//            }
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//}
